<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class DeviceFault extends Model
{
    use SoftDeletes;
    
    protected $fillable = [
        'device_id',
        'fault_code',
    ];

    protected $dates = ['deleted_at'];

    protected $appends = [
        'device_fault_description',
    ];

    public function getDeviceFaultDescriptionAttribute()
    {
        if(array_key_exists('fault_code', $this->attributes)){
            $falutCode = $this->attributes['fault_code'];
            return config("heting.fault.$falutCode");
        }
    }

    public function device()
    {
        return $this->belongsTo('App\Models\Device', 'device_id', 'id');
    }
}
